import time
from threading import Thread, current_thread, Lock

ticket = 50
lock = Lock()

def sale_ticket():
    global ticket
    # 3个队伍，每个队伍60人排队买票
    for i in range(60):
        lock.acquire()
        if ticket > 0:
            print(f'{current_thread().name}正在出售第{ticket}张票')
            ticket -= 1
        time.sleep(1)
        lock.release()

if __name__ == '__main__':
    lst = [Thread(target=sale_ticket) for _ in range(3)]
    for t in lst:
        t.start()
    for t in lst:
        t.join()
